package com.ruoyi.ichen.rabbitmq.day4_direct;

import com.rabbitmq.client.*;
import com.ruoyi.ichen.rabbitmq.common.RabbitMQUtils;

import java.io.IOException;

public class Customer1 {


    public static void main(String[] args) throws IOException {

        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();

        //通道生命交换机以及交换的类型
        channel.exchangeDeclare("ichen_direct","direct");

        //创建临时队列
        String queue = channel.queueDeclare().getQueue();

        //基于route key 绑定队列和交换机
        channel.queueBind(queue,"ichen_direct","error");
        channel.queueBind(queue,"ichen_direct","debug");
        channel.queueBind(queue,"ichen_direct","info");
        channel.queueBind(queue,"ichen_direct","warnning");

        //获取消息
        channel.basicConsume(queue,true,new DefaultConsumer(channel){

            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.out.println("消费者1-------->" + new String(body));
            }
        });


    }
}
